package client;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.*;

public class usernameFrame extends JFrame implements ActionListener {
	public JFrame frame;
	private JButton jButton1;
	private JLabel jLabel1;
	private JPanel jPanel1;
	private JTextField jTextField1;

	public usernameFrame() {

		frame = new JFrame();
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setTitle("Enter a Username");
		frame.setSize(300, 150);
		frame.setLocationRelativeTo(null);

		jPanel1 = new JPanel(new BorderLayout());

		JPanel jPanel2 = new JPanel();
		jLabel1 = new JLabel("Please enter a username:");
		jPanel2.add(jLabel1);
		jPanel1.add(jPanel2, BorderLayout.NORTH);

		JPanel jPanel3 = new JPanel();
		jTextField1 = new JTextField();
		jTextField1.setPreferredSize(new Dimension(100, 20));
		jTextField1.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent ke) {
				if (ke.getKeyCode() == ke.VK_ENTER) {
					if (!(jTextField1.getText().equals("")))
						actionPerformed(null);
				}
			}
		});
		jPanel3.add(jTextField1);
		jPanel1.add(jPanel3, BorderLayout.CENTER);

		JPanel jPanel4 = new JPanel();
		jButton1 = new JButton("Submit");
		jButton1.addActionListener(this);
		jPanel4.add(jButton1);
		jPanel1.add(jPanel4, BorderLayout.SOUTH);

		frame.add(jPanel1);
		frame.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		if (!(jTextField1.getText().equals(""))) {
			String username = jTextField1.getText();
			System.out.println("1");
			mainFrame a =new mainFrame(username);
			System.out.println("2");
			a.setVisible(true);
			System.out.println("3");
			frame.setVisible(false);
		}
	}
}
